package com.shop.common;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

import java.io.Serializable;

@Data
@JsonInclude(JsonInclude.Include.ALWAYS)
public class SetMeta<T> implements Serializable {
    private T data;
    private Meta meta;

    public SetMeta() {
        this.meta=new Meta();
    }

    public SetMeta(T data, Meta meta) {
        this.data = data;
        this.meta = meta;
    }

    public void setSuccess(T data) {
        this.data = data;
        this.meta.setStatus(ResponseCode.SUCCESS.getCode());
        this.meta.setMsg(ResponseCode.SUCCESS.getMessage());
    }

    public void setSuccess(String msg) {
        this.meta.setStatus(ResponseCode.SUCCESS.getCode());
        this.meta.setMsg(msg);
    }

    public void setSuccess(T data, String msg) {
        this.data = data;
        this.meta.setStatus(ResponseCode.SUCCESS.getCode());
        this.meta.setMsg(msg);
    }

    public void setCreated(T data) {
        this.data = data;
        this.meta.setStatus(ResponseCode.CREATED.getCode());
        this.meta.setMsg(ResponseCode.CREATED.getMessage());
    }

    public void setCreated(T data, String msg) {
        this.data = data;
        this.meta.setStatus(ResponseCode.CREATED.getCode());
        this.meta.setMsg(msg);
    }

    public void setError() {
        this.meta.setStatus(ResponseCode.ERROR.getCode());
        this.meta.setMsg(ResponseCode.ERROR.getMessage());
    }

    public void setError(String msg) {
        this.meta.setStatus(ResponseCode.ERROR.getCode());
        this.meta.setMsg(msg);
    }
}